<template>
  <el-dialog
    title="选择试卷"
    :visible.sync="open"
    :before-close="close">

    <el-form :inline="true">
      <el-form-item>
        <el-select
          v-model="queryTags"
          multiple
          collapse-tags
          style="margin-left: 20px;"
          placeholder="请选择标签后查询">
          <el-option
            v-for="item in tags"
            :key="item.id"
            :label="item.tagName"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getList"> 搜索</el-button>
      </el-form-item>
    </el-form>


    <el-table :data="dataList" v-loading="loading" @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55"/>
      <el-table-column label="试卷名称" prop="name"/>
      <el-table-column label="描述" prop="name"/>
      <el-table-column label="总分" prop="fraction"/>
      <el-table-column label="标签" prop="name"/>
    </el-table>
    <div style="text-align: right; margin-top: 20px">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submit(selected)">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {testPaperList} from "@/api/edu/trainPlan";

export default {
  name: 'testPaper',
  props: {
    open: {
      type: Boolean,
      default: false
    },
    close: {
      type: Function,
      default: () => {
      }
    },
    submit: {
      type: Function,
      default: () => {
      }
    },
    tags: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      loading: false,
      queryTags: [],
      dataList: [],
      selected: []
    }
  },
  methods: {
    getList() {
      this.loading = true
      testPaperList(this.queryTags.toString()).then(res => {
        this.dataList = res.data
        this.loading = false
      })
    },
    handleSelectionChange(val) {
      this.selected = val
    }
  }
}
</script>

<style scoped>

</style>
